<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>FileReference2</title>
<style type="text/css">
	body{
		font-family:Arial;
		font-size:0.75em;
		margin:50px;
		}
	ul	{
		height:150px;
		width:300px;
		overflow-y:scroll;
		border:2px inset;
		list-style:none;
		padding:0;
		margin:0;
		}
	ul li
		{
		padding:3px;
		margin:0;
		list-style:none;
		border-bottom:1px solid #EAEAEA;
		}
	ul label
		{
		display:block;
		}
	ul li.checked
		{
		background:#FFFFEA;
		}
	ul a
		{
		float:right;
		}
	ul li.clone
		{
		display:none;
		}
</style>
<script type="text/javascript">
	
	
	compono.HTMLElements.input.upload = function(proto)
	{
		this.onOpen = proto.onOpen || function(){return true};
		this.onComplete = proto.onComplete || function(){return true};
		
		this.form.caller = this;
		
		$(this.form).event('submit',function(event)
		{
			if(this.caller && this.caller.onOpen && this.caller.onOpen.call(this.caller, event) == false){
				event.preventDefault();
				return false;
			};

			if(!this.frame)
			{
				var div = $(this).append("div");

				var target = 'fileUpload' + Math.floor(Math.random() * 99999);
				
				div.append("<iframe src='about:blank' id='" + target +"' name='" + target +"' onload='if(this.uploadReady){this.uploadReady(event)}' style='display:none;position:absolute;bottom:0;right:0' ></iframe>");
				
				div.append("<input type='hidden' name='AjaxApp' value='COMPONO' />");
				
				this.frame = div.first();

				this.frame.caller = this.caller;

				this.frame.uploadReady = function()
				{
					var doc = this.contentDocument || this.contentWindow.document || window.frames[this.id].document;
					
					if (doc.location.href == "about:blank"){
						return;
					};
					
					var complete = this.caller.onSuccess || this.caller.onComplete;
					
					var content = doc.body.textContent || doc.body.innerHTML;
					
					if(this.caller && complete && complete.call(this.caller, event, content) == false){
						return false;
					};
					
				};
				
				this.attr("target", target);
				this.attr("method", "POST");
				this.attr("enctype", "multipart/form-data");
				this.attr("encoding", "multipart/form-data");
			}
		});
	}

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	function Flash(id){
		return (window.attachEvent?window:document)[id];
	}
	
	function FBrowse(){
		console.log(Flash("FileReference2").browse([{
			description:"Imagens",
			extension:"*.jpg;*.psd;*.png;*.jpeg;*.gif;*.tiff"
		}]))
	}
	
	function FUpload(){
		var a = document.getElementsByName("files");
		var r=[];
		for(var i=0;i<a.length;i++){
			if(a[i].checked){
				r[r.length] = a[i].parentNode.parentNode.file;
			}
		}
		Flash("FileReference2").upload("http://www.terra.com.br",r);
	}
	
	function FonSelect(args){
		var o = document.getElementById("output");
		var li = o.getElementsByTagName("li")[0];
		for(var i=0,a,s;i<args.length;i++){
			a = o.appendChild(li.cloneNode(true));
			a.className='';
			a.file = args[i];
			s = a.getElementsByTagName("span")[0];
			s.innerHTML = a.file.name;
		}
	}
	
	function FonCancel(args){
		console.log(args);
	}
	
	var compono={
		set:function(k){
			console.log(k);
		}
	}
		
		
		
</script>
</head>
<body>
<input type="button" onclick="FBrowse()" value="FBrowse()" />
<br />
<object id="FileReference2" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="300" height="150" >
	<param name="allowScriptAccess" value="always" />
	<param name="movie" value="FileReference2.swf" />
	<param name="quality" value="high" />
	<param name="bgcolor" value="#ffffff" />
	<embed name="FileReference2" src="FileReference2.swf" quality="high" width="300" height="150" 
		allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>

<ul id="output">
	<li class="clone">
		<a href="javascript:void(0)" onclick="this.parentNode.parentNode.removeChild(this.parentNode)">remove</a>
		<label><input type="checkbox" name="files" onchange="this.parentNode.parentNode.className=this.checked?'checked':''" /><span></span></label>
	</li>
</ul>
<input type="button" onclick="FUpload()" value="FUpload()" />
</body>
</html>
